extends ../layout

block content
    .container
        .row
            table.table.table-hover.table-bordered
                thead
                    tr
                        th 名称
                        th 修改
                        th 更新时间
                        th 删除
                tbody
                    if categories && categories.length
                        each item in categories
                            tr(class='item-id-' + item._id)
                                td #{item.name}
                                td: a(target='_blank', href='/admin/category/update/' + item._id) 修改
                                td #{moment(item.updatedAt).format('MM/DD/YYYY')}
                                td
                                    button.btn.btn-danger.del(type='button', data-id=item._id) 删除
    script.
        $(function () {
            $('.del').click(function (e) {
                var target = $(e.target)
                var id = target.data('id')
                var tr = $('.item-id-' + id)

                $.ajax({
                    type: 'DELETE',
                    url: '/admin/category?id=' + id
                })
                    .done(function (results) {
                        if (results.success) {
                            if (tr.length >= 1) {
                                tr.remove()
                            }
                        }
                    })
            })
        })